/*
 * CAnimationCollection.cpp
 *
 *  Created on: 06.01.2012
 *      Author: Kirill Blinov
 *      Copyright: LGPL
 */

#include "CAnimationCollection.h"
#include "AnimationFabric.h"

CAnimationCollection::CAnimationCollection() : currentMoving(NULL), currentRotation(NULL)
{

}

CAnimationCollection::~CAnimationCollection()
{
	controllers.clean();
}

void
CAnimationCollection::Animate( IAnimationPlayer* Player, UNIT_PHYSIC_PARAMS* PhysicParams )
{
	if ( currentMoving.deleteController )
	{
		StopBuiltinAnimation( currentMoving );
	}

	if ( currentRotation.deleteController )
	{
		StopBuiltinAnimation( currentRotation );
	}

	for( std::list<IAnimationController*>::iterator it = controllers.begin();
		 it != controllers.end(); it++ )
	{
		IAnimationController* Controller = *it.base();
		Controller->Animate( Player, PhysicParams );
	}
}

bool
CAnimationCollection::PlayAnimation( const UINT AnimationID, const float Speed, const bool Cyclic )
{
	bool Result = AnimationFabric::IsAnimationExist( AnimationID );

	if (Result)
	{
		IAnimationController* NewController = AnimationFabric::CreateAnimation( AnimationID, Speed, Cyclic );
	}
	return Result;
}

void
CAnimationCollection::Rotate( const float Angle, const glm::vec3 Axis )
{

}

void
CAnimationCollection::StopRotation( )
{
	currentRotation.deleteController = true;
}

void
CAnimationCollection::Move( const float Acceleration, const glm::vec3 Direction )
{

}

void
CAnimationCollection::SetSpeed( const float speed )
{

}

void
CAnimationCollection::StopMoving()
{
	currentMoving.deleteController = true;
}

void
CAnimationCollection::StopBuiltinAnimation( CollectionControllerState& Controller, IAnimationPlayer* Player )
{
	controllers.erase( Controller.controller );
	Controller.controller = controllers.end();
	Controller.deleteController = false;
}
